/**
 * Copyright (c) 2020 xstgongyi.org
 * All rights reserved.
 */
package org.xstgongyi.eduaid.manager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.xstgongyi.eduaid.dao.SchoolYearMapper;
import org.xstgongyi.eduaid.dataobject.SchoolYearDO;

import java.util.List;

/**
 * @author oldcrane
 * @created 2020-10-12
 */
@Service
@CacheConfig(cacheNames="school-year")
public class SchoolYearManager {

    @Autowired
    private SchoolYearMapper dao;

    // not cached
    public List<SchoolYearDO> listAll() {
        return dao.listAll();
    }

    @Cacheable(key="'list-status-' + #active")
    public List<SchoolYearDO> listAllByStatus(Boolean active) {
        return dao.listAllByStatus(active);
    }

    @Cacheable(key = "#id")
    public SchoolYearDO getById(Integer id){
        return dao.getById(id);
    }

    @CacheEvict(allEntries = true)
    public int insert(SchoolYearDO schoolYear) {
        return dao.insert(schoolYear);
    }

    @CacheEvict(allEntries = true)
    public int update(SchoolYearDO schoolYear){
        return dao.update(schoolYear);
    }

}
